﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace InternshipManagement.Models
{
    public class DashboardRepository
    {
        private InternshipEntities entities = new InternshipEntities();


        public IQueryable<Dashboard> FindAllByUserTypeID(int UserTypeID)
        {
            return from dashboard in entities.Dashboards
                   join auth in entities.DashboardAuths on dashboard.ID equals auth.DashboardID
                   where auth.UserTypeID == UserTypeID
                   orderby dashboard.Order
                   select dashboard;
        }

        public void AddDashboardAuth(DashboardAuth d)
        {
            entities.DashboardAuths.AddObject(d);
        }

        public void RemoveAllByUserTypeID(int UserTypeID)
        {
            foreach (DashboardAuth d in entities.DashboardAuths.Where(da => da.UserTypeID == UserTypeID))
            {
                entities.DashboardAuths.DeleteObject(d);
            }
        }



        //
        // Persistence
        public void Save()
        {
            entities.SaveChanges();
        }
    }
}